export const getDefaultProgramId = (programList, username) => {
  for (let i = 0; i < programList.length; i++) {
    let item = programList[i];
    let reg = new RegExp(`^${username}\\d+$`);
    if (reg.test(item.title)) {
      return item.id;
    }
  }
  return programList[0].id;
};

export const getDataSource = (data) => {
  const columnData = (data?.head || []).map((t) => {
    return {
      unitId: t.stationId,
      unitTitle: t.stationName,
    };
  });
  const dataSource = [];
  Object.entries(data?.tableData || {})?.forEach((t) => {
    const obj = { date: t[0] };
    t[1].forEach((item) => {
      Object.keys(item).forEach((key) => {
        if (key === 'date') return;
        obj[`${item['stationId']}_${key}`] = item[key];
      });
    });
    dataSource.push(obj);
  });
  return { columnData, dataSource };
};
export const exportColumns = [
  { header: '日期', key: 'hourOrder', width: '14' },
  { header: '交易方向', key: 'tradeStrategy', width: '14' },
  { header: '价格上限(元/MWh)', key: 'upperPrice', width: '28' },
  { header: '价格下限(元/MWh)', key: 'lowerPrice', width: '28' },
  {
    header: '申报电量',
    children: [
      {
        header: '参考值',
        key: 'submitType',
        width: '28',
      },
      {
        header: '比例(%)',
        key: 'firstSubmitPower',
        width: '14',
      },
      {
        header: '固定值(MWh)',
        key: 'fixedValue',
        width: '14',
      },
    ],
  },
  { header: '申报电价(元/MWh)', key: 'firstPrice', width: '28' },
  { header: '申报总电量(MWh)', key: 'totalPower', width: '28' },
];
